package com.qing;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;

/**
 * Created by wuliao on 2017/8/15.
 */
public class Request{
    private HashSet<String> andList = new HashSet<>();
    private HashSet<String> orList = new HashSet<>();
    private HashSet<String> notList = new HashSet<>();
    private HashSet<String> values = new HashSet<>();
    private String key;

    public Request(String key){
        this.key = key;
    }

    public void dealStr(String str){
        values.add(str);

        while(str.length()>0){
            if(!str.startsWith("AND")&&!str.startsWith("OR")&&!str.startsWith("NOT")){
                int position = str.indexOf(" ");
                if(position!=-1){
                    String and = str.substring(0,position);
                    andList.add(and);
                    str = str.replaceFirst(and,"").trim();
                }else{
                    andList.add(str);
                    str = str.replaceFirst(str,"").trim();
                }
            }else if(str.startsWith("AND")){
                str = str.replaceFirst("AND ","");
                int position = str.indexOf(" ");
                if(position!=-1){
                    String and = str.substring(0,position);
                    andList.add(and);
                    str = str.replaceFirst(and,"").trim();
                }else{
                    andList.add(str);
                    str = str.replaceFirst(str,"").trim();
                }
            }else if(str.startsWith("OR")){
                str = str.replaceFirst("OR ","");
                int position = str.indexOf(" ");
                if(position!=-1){
                    String or = str.substring(0,position);
                    orList.add(or);
                    str = str.replaceFirst(or,"").trim();
                }else{
                    orList.add(str);
                    str = str.replaceFirst(str,"").trim();
                }
            }else if(str.startsWith("NOT")){
                str = str.replaceFirst("NOT ","");
                int position = str.indexOf(" ");
                if(position!=-1){
                    String or = str.substring(0,position);
                    notList.add(or);
                    str = str.replaceFirst(or,"").trim();
                }else{
                    notList.add(str);
                    str = str.replaceFirst(str,"").trim();
                }
            }else{
                throw new IllegalArgumentException("非法的参数异常");
            }
        }
    }



}
